package com.mz.ozy.mvp.presenter;


import android.app.Activity;
import android.content.Context;

import com.mz.ozy.base.BasePresenterImpl;
import com.mz.ozy.bean.RoleListBean;
import com.mz.ozy.bean.SwitchRoleBean;
import com.mz.ozy.mvp.model.SwitchRoleModel;
import com.mz.ozy.mvp.view.SwitchRoleContract;
import com.mz.ozy.net.MyObserver;
import com.mz.ozy.utils.RxUtil;

import okhttp3.ResponseBody;

/**
 * Created by administrator on 2018/12/3.
 */
public class SwitchRolePresenter extends BasePresenterImpl<SwitchRoleContract.View> implements SwitchRoleContract.Presenter {

    private SwitchRoleModel mModel;

    public SwitchRolePresenter() {
        mModel = new SwitchRoleModel();
    }


    @Override
    public void getRoleLevelList(Activity activity) {
        mModel.getRoleLevelList(activity)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<RoleListBean>(mView) {
                    @Override
                    public void onSuccesss(RoleListBean json) {
                        mView.getRoleListSuccess(json);
                    }
                });
    }

    @Override
    public void addRole(Context context, String nickName, String inviteCode) {
        mModel.addRole(context, nickName, inviteCode)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<RoleListBean>(mView) {
                    @Override
                    public void onSuccesss(RoleListBean json) {
                        mView.addRoleSuccess(json);
                    }
                });
    }

    @Override
    public void switchRoles(Context context, String uname) {
        mModel.switchRoles(context, uname)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<SwitchRoleBean>(mView) {
                    @Override
                    public void onSuccesss(SwitchRoleBean bean) {
                        mView.switchRolesSuccess(bean);
                    }
                });
    }
}
